<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.etc.controller.*" %>
<%@page import="com.etc.entity.*" %>
<%@page import="com.etc.dao.*" %>
<%@page import="com.etc.service1.*" %>
<%@page import="com.etc.service.impl.*" %>
<%@page import="java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>论坛</title>
<link rel="icon" type="image/x-icon" href="img/sheep.ico" />
<link rel="stylesheet" type="text/css" href="css/messagedetail.css" />
</head>
<body>
<%
	request.setCharacterEncoding("UTF-8");
	AnsAnswerServiceDao aadao = new AnsAnswerServiceDaoImpl();
	Message upmessage = (Message)request.getSession().getAttribute("message");
	List<AnsMessage> list = (List<AnsMessage>)request.getSession().getAttribute("anslist");
	
	String username = (String)request.getSession().getAttribute("username");
	String userrole = (String)request.getSession().getAttribute("userrole");
	//String jin_info = (String)request.getSession().getAttribute("jin_info");
	String mytietip = request.getParameter("mytietip");
	int flag=0;
	int upid=0;
	int floorid=0;
	int sum=0;
	upid = upmessage.getId();
%>
 	    <div id="up">
	 			    <font class="title"><%=upmessage.getTitle() %></font>
	 	    		<p class="name"><b><%=upmessage.getUsername() %></b>&nbsp;&nbsp;&nbsp;&nbsp;<font class="date"><%=upmessage.getDate() %></font></p>
	 	    		<p class="cont">&nbsp;&nbsp;<%=upmessage.getContent() %></p>
 	    		 <% 
 	    			if("user"==userrole||"user".equals(userrole))
 	    			{
 	    				if(upmessage.getUsername()==username||upmessage.getUsername().equals(username))
 	    				{
 	    					flag=1;
 	    		%>
 	    			<div class="caozuo">
		 	    		<form action="AnsMessageServlet?am=answer" method="post">
		 	    				<input type="hidden" value="<%=upmessage.getTitle() %>" name="title">
		 	    				<input type="hidden" value="<%=upmessage.getId() %>" name="ansid">
		 	    				<input type="hidden" value="<%=upmessage.getType() %>" name="type">
		 	    				<input type="hidden" value="<%=username %>" name="username">
		 	    				<input type="button" value="回复" class="hide1">
		 	    				<div class="hf hide">
		 	    				
 	 	    					<input type="text" name="content"  id="content" style="background:transparent;line-height:30px;margin-left:20px;font-size:14px;font-family:'微软雅黑';border:1px solid black" size="100">
	 	 	    				<input class="hui" type="submit" value="回复">
	 	 	    				</div>
		 	    				<span class="shan"><a href="MessageServlet?po=del&mytietip=<%=mytietip %>&title=<%=upmessage.getTitle() %>&id=<%=upmessage.getId()%>">&nbsp;删除</a></span>
 	 	    			</form>
 					</div>
 	    		<%
 	    				}
 	 	    			else
 	 	    			{
 	 	    	%>
 	 	    			<div class="caozuo">
 	 	    				<form action="AnsMessageServlet?am=answer" method="post">
 	 	    					<input type="hidden" value="<%=upmessage.getTitle() %>" name="title">
		 	    				<input type="hidden" value="<%=upmessage.getId() %>" name="ansid">
		 	    				<input type="hidden" value="<%=upmessage.getType() %>" name="type">
		 	    				<input type="hidden" value="<%=username %>" name="username">
		 	    				<input type="button" value="回复" class="hide1">
 	 	    				    <div class="hf hide">
 	 	    					<input type="text" name="content"  id="content" style="background:transparent;line-height:30px;margin-left:20px;font-size:14px;font-family:'微软雅黑';border:1px solid black" size="100">
	 	 	    				<input class="hui" type="submit" value="回复">
	 	 	    				</div>
 	 	    				</form>
 	 					</div>
 	 	    	<%
 	 	    		}
 	    			}
 	    			else if("admin"==userrole||"admin".equals(userrole))
 	    			{		
 	    		%>
 	    			<div class="caozuo">
		 	    		<form action="AnsMessageServlet?am=answer" method="post">
 	 	    					<input type="hidden" value="<%=upmessage.getTitle() %>" name="title">
		 	    				<input type="hidden" value="<%=upmessage.getId() %>" name="ansid">
		 	    				<input type="hidden" value="<%=upmessage.getType() %>" name="type">
		 	    				<input type="hidden" value="<%=username %>" name="username">
		 	    				<input type="button" value="回复" class="hide1">
 	 	    					<div class="hf hide">
 	 	    					<input type="text" name="content"  id="content" style="background:transparent;line-height:30px;margin-left:20px;font-size:14px;font-family:'微软雅黑';border:1px solid black" size="100">
	 	 	    				<input class="hui" type="submit" value="回复">
	 	 	    				</div>
		 	    				<span class="shan"><a href="MessageServlet?po=del&mytietip=<%=mytietip %>&title=<%=upmessage.getTitle() %>&id=<%=upmessage.getId()%>">&nbsp;删除</a></span>
 						<%
 							if("正常"==upmessage.getStatus()||"正常".equals(upmessage.getStatus()))
 							{
 						%>
 							<span class="jie"><a href="MessageServlet?po=fengmes&id=<%=upmessage.getId()%>&title=<%=upmessage.getTitle()%>">&nbsp;封禁</a></span>
 	 	    			<%
 							}
 	 	    				else if("封禁"==upmessage.getStatus()||"封禁".equals(upmessage.getStatus()))
 	 	    				{
 	 	    			%>
 	 	    				<span class="jie"><a href="MessageServlet?po=jiemes&id=<%=upmessage.getId()%>&title=<%=upmessage.getTitle()%>">&nbsp;解禁</a></span>
 	 	    			<%
 	 	    				}
 	 	    			%>
 	 	    			</form>
 					</div>
 	    		<%
 	    			}
 	    		%>
 	    </div>
<%
	int xuhao=0;
	for(int i=0;i<list.size();i++)
	{
		if(upid==list.get(i).getAnsid())
		{
			xuhao+=1;
			floorid=list.get(i).getId();
			
			List<AnsAnswer> ansanslist=aadao.findAnswerAnsMessage(floorid);
			
			if(list.get(i).getStatus()=="正常"||list.get(i).getStatus().equals("正常"))
			{
%>
			<div class="ans">
			 	   		<p class="name">&nbsp;<%=xuhao %>&nbsp;<b>&nbsp;<%=list.get(i).getUsername() %></b>&nbsp;&nbsp;&nbsp;<font class="date"><%=list.get(i).getDate() %></font></p>
			 	    	<font class="cont">&nbsp;&nbsp;&nbsp;<%=list.get(i).getContent() %></font>
		 	    <% 
 	    			if("user"==userrole||"user".equals(userrole))
 	    			{
 	    				if(flag==1)
 	    				{
 	    		%>
 	    			<div class="caozuo">
 	 	    				<form action="AnsAnswerServlet?aa=answer" method="post">
 	 	    					<input type="hidden" value="<%=upid%>" name="upid">
 	 	    					<input type="hidden" value="<%=list.get(i).getId() %>" name="ansid">
 	 	    					<input type="hidden" value="<%=list.get(i).getTitle() %>" name="title">
		 	    				<input type="hidden" value="<%=list.get(i).getType() %>" name="type">
		 	    				<input type="hidden" value="<%=username %>" name="username">
		 	    				<input type="button" value="回复" class="hide1">
 	 	    					<div class="hf hide">
 	 	    					<input type="text" name="content"  id="content" style="background:transparent;line-height:30px;margin-left:20px;font-size:14px;font-family:'微软雅黑';border:1px solid black" size="100">
	 	 	    				<input class="hui" type="submit" value="回复">
	 	 	    				</div>
		 	    		<span class="shan"><a href="AnsMessageServlet?am=del&title=<%=list.get(i).getTitle() %>&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;删除</a></span>
 	 	    				</form>
 					</div>
 	    		<%
 	    				}
 	    				else if(list.get(i).getUsername()==username||list.get(i).getUsername().equals(username))
 	    				{
 	    		%>
 	    			<div class="caozuo">
 	    				<form action="AnsAnswerServlet?aa=answer" method="post">
 	 	    					<input type="hidden" value="<%=upid%>" name="upid">
 	 	    					<input type="hidden" value="<%=list.get(i).getId() %>" name="ansid">
 	 	    					<input type="hidden" value="<%=list.get(i).getTitle() %>" name="title">
		 	    				<input type="hidden" value="<%=list.get(i).getType() %>" name="type">
		 	    				<input type="hidden" value="<%=username %>" name="username">
		 	    				<input type="button" value="回复" class="hide1">
 	 	    					<div class="hf hide">
 	 	    					<input type="text" name="content"  id="content" style="background:transparent;line-height:30px;margin-left:20px;font-size:14px;font-family:'微软雅黑';border:1px solid black" size="100">
	 	 	    				<input class="hui" type="submit" value="回复">
	 	 	    				</div>
		 	    		<span class="shan"><a href="AnsMessageServlet?am=del&title=<%=list.get(i).getTitle() %>&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;删除</a></span>
 	 	    				</form>
 					</div>
 	    		<%
 	    				}
 	    				else
 	    				{
 	    	 	    		%>
 	    	 	    			<div class="caozuo">
 	    	 	 	    				<form action="AnsAnswerServlet?aa=answer" method="post">
			 	 	    					<input type="hidden" value="<%=upid%>" name="upid">
			 	 	    					<input type="hidden" value="<%=list.get(i).getId() %>" name="ansid">
 	    	 	 	    					<input type="hidden" value="<%=list.get(i).getTitle() %>" name="title">
 	    			 	    				<input type="hidden" value="<%=list.get(i).getType() %>" name="type">
 	    			 	    				<input type="hidden" value="<%=username %>" name="username">
 	    			 	    				<input type="button" value="回复" class="hide1">
 	    	 	 	    					<div class="hf hide">
 	 	    					<input type="text" name="content"  id="content" style="background:transparent;line-height:30px;margin-left:20px;font-size:14px;font-family:'微软雅黑';border:1px solid black" size="100">
	 	 	    				<input class="hui" type="submit" value="回复">
	 	 	    				</div>
 	    	 	 	    				</form>
 	    	 					</div>
 	    	 	    		<%
 	    	 	    				}
 	    			}
 	    			else if("admin"==userrole||"admin".equals(userrole))
 	    			{		
 	    		%>
 	    			<div class="caozuo">
 	    				<form action="AnsAnswerServlet?aa=answer" method="post">
 	 	    					<input type="hidden" value="<%=upid%>" name="upid">
 	 	    					<input type="hidden" value="<%=list.get(i).getId() %>" name="ansid">
 	 	    					<input type="hidden" value="<%=list.get(i).getTitle() %>" name="title">
		 	    				<input type="hidden" value="<%=list.get(i).getType() %>" name="type">
		 	    				<input type="hidden" value="<%=username %>" name="username">
		 	    				<input type="button" value="回复" class="hide1">
 	 	    					<div class="hf hide">
 	 	    					<input type="text" name="content"  id="content" style="background:transparent;line-height:30px;margin-left:20px;font-size:14px;font-family:'微软雅黑';border:1px solid black" size="100">
	 	 	    				<input class="hui" type="submit" value="回复">
	 	 	    				</div>
		 	    		<span class="shan"><a href="AnsMessageServlet?am=del&title=<%=list.get(i).getTitle() %>&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;删除</a></span>
 						<span class="jie"><a href="AnsMessageServlet?am=fengans&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;封禁</a></span>
 	 	    				</form>
 					</div>
 	    		<%
 	    			}
 	    		%>
 	    		 <div class="ansans">
	 				<%
	 				sum=0;
	 				for( int j=0;j<ansanslist.size();j++)
	 				{
	 					if(floorid==ansanslist.get(j).getAnsid())
	 					{
	 						sum++;
	 						if((ansanslist.get(j).getStatus()=="正常"||ansanslist.get(j).getStatus().equals("正常")))
	 						{
		 						if(sum<=2)
		 						{
		 				%>
		 						<p class="name"><b>&nbsp;<%=ansanslist.get(j).getUsername() %></b>&nbsp;&nbsp;&nbsp;<font class="date"><%=ansanslist.get(j).getDate() %></font></p>
					 	    	<font class="cont">&nbsp;&nbsp;&nbsp;<%=ansanslist.get(j).getContent() %></font>
		 				<%
		 						}
	 						}
	 					}
	 				}
	 				if(sum>0)
		 				{
		 				%>
		 				<p><a href="answer_ans.jsp?ansname=<%=list.get(i).getUsername() %>&ansid=<%=list.get(i).getId() %>" class="ckpl" style="color:#666">查看全部<%=sum %>条评论</a></p>
		 				<%
		 				}
	 				else
	 					{
		 				%>
		 				<p><a href="answer_ans.jsp?ansname=<%=list.get(i).getUsername() %>&ansid=<%=list.get(i).getId() %>" class="ckpl" style="color:#666">当前没有评论，去评论</a></p>
		 				<%
		 				}
		 				%>
 				</div> 
 			</div>
 <%				
			}
			else
			{
%>
			<div class="ans">
 	    	<p class="name" style="color:red">&nbsp;<%=xuhao %>&nbsp;<b>&nbsp;<%=list.get(i).getUsername() %></b>&nbsp;&nbsp;&nbsp;<font class="date" style="color:red"><%=list.get(i).getDate() %></font></p>
 	    	<font class="cont" style="color:red">&nbsp;&nbsp;用户发言涉嫌违规内容，已屏蔽该内容</font>
 	    		<%
 	    			if("admin"==userrole||"admin".equals(userrole))
	    			{		
	    		%>
	    			<div class="caozuo">
		 	    		<span class="shan"><a href="AnsMessageServlet?am=del&title=<%=list.get(i).getTitle() %>&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;删除</a></span>
 						<span class="jie"><a href="AnsMessageServlet?am=jieans&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;解禁</a></span>
					</div>
	    		<%
	    			}
 	    			else if(flag==1)
 	    			{
 	    				%>
 	    			<div class="caozuo">
		 	    		<span class="shan"><a href="AnsMessageServlet?am=del&title=<%=list.get(i).getTitle() %>&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;删除</a></span>
 					</div>
 	    		<%
					}
	    		%> 
	    		 <div class="ansans">
	 				<%
	 				sum=0;
	 				for( int j=0;j<ansanslist.size();j++)
	 				{
	 					if(floorid==ansanslist.get(j).getAnsid())
	 					{
	 						sum++;
	 						if((ansanslist.get(j).getStatus()=="正常"||ansanslist.get(j).getStatus().equals("正常")))
	 						{
		 						if(sum<=2)
		 						{
		 				%>
		 						<p class="name"><b>&nbsp;<%=ansanslist.get(j).getUsername() %></b>&nbsp;&nbsp;&nbsp;<font class="date"><%=ansanslist.get(j).getDate() %></font></p>
					 	    	<font class="cont">&nbsp;&nbsp;&nbsp;<%=ansanslist.get(j).getContent() %></font>
		 				<%
		 						}
	 						}
	 					}
	 				}
	 				if(sum>0)
		 				{
		 				%>
		 				<p><a href="answer_ans.jsp?ansname=<%=list.get(i).getUsername() %>&ansid=<%=list.get(i).getId() %>" class="ckpl" style="color:#666">查看全部<%=sum %>条评论</a></p>
		 				<%
		 				}
	 				else
	 					{
		 				%>
		 				<p><a href="answer_ans.jsp?ansname=<%=list.get(i).getUsername() %>&ansid=<%=list.get(i).getId() %>" class="ckpl" style="color:#666">当前没有评论，去评论</a></p>
		 				<%
		 				}
		 				%>
 				</div> 
 			</div>
<%			
			}
		}
	}
%>
</body>
<script src="js/jquery-2.1.1.min.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript">
$(".hide1").click(function(){
	$(".hide").toggle("hide");
})
</script>
</html>